package com.fary.validator;

import com.fary.vo.User;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.validation.Errors;
import org.springframework.validation.FieldError;
import org.springframework.validation.ValidationUtils;

import java.util.List;

public class DataValidateTest {
    public static void main(String[] args) {
        User person = new User();
        person.setAge(120);
        Errors errors = new BeanPropertyBindingResult(person, User.class.getSimpleName());
        ValidationUtils.invokeValidator(new UserValidator(), person, errors);
        System.out.println(errors.getErrorCount());
        List<FieldError> fieldErrors = errors.getFieldErrors();
        for (FieldError fieldError : fieldErrors) {
            System.out.println(fieldError.getField() + ":" + fieldError.getCode());
        }
    }
}
